package com.bibrApp.difu.base;

import android.content.Context;

import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.android.FragmentEvent;

/**
 * @date 2020/2/11
 * @author dj
 * @param <T>
 */
public class BasePresenter<T extends IBaseView> {
    public Context context;
    public T iView;

    public BasePresenter(Context context, T iView) {
        this.context = context;
        this.iView = iView;

    }

    /**
     * 初始化
     */
    public void init() {
        iView.initView();
    }

    /**
     * 对 ACTIVITY 生命周期进行管理
     *
     * @return
     */
    protected LifecycleProvider<ActivityEvent> getActivityLifecycleProvider() {
        LifecycleProvider<ActivityEvent> provider = null;
        if (null != context && context instanceof LifecycleProvider) {
            provider = (LifecycleProvider<ActivityEvent>) context;
        }
        return provider;
    }

    protected LifecycleProvider<FragmentEvent> getFragmentLifecycleProvider() {
        LifecycleProvider<FragmentEvent> provider = null;
        if (null != context && context instanceof LifecycleProvider) {
            provider = (LifecycleProvider<FragmentEvent>) context;
        }
        return provider;
    }
}
